package com.yjq.client.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seventh.common.pojo.R;
import com.yjq.client.mapper.ClientMapper;
import com.yjq.client.poji.entry.TbClient;
import com.yjq.client.poji.vo.ClientVo;
import com.yjq.client.service.ClientService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: clms-seventh
 * @description: ClientService的实现
 * @author: 杨佳琪
 * @create: 2021-07-23 11:35
 **/
@Service
public class ClientServiceImpl implements ClientService {
    @Resource
    private ClientMapper clientMapper;

    @Override
    public R findAllClientByPage(Integer currentPage, Integer pageSize, ClientVo clientVo) {
        Page<TbClient> page=new Page<>(currentPage,pageSize);
        QueryWrapper<TbClient> wrapper=new QueryWrapper<>();
        if (StringUtils.isNotEmpty(clientVo.getEmail())){
            wrapper.like("email",clientVo.getEmail());
        }
        if (StringUtils.isNotEmpty(clientVo.getPhoneNum())){
            wrapper.like("phone_num",clientVo.getPhoneNum());
        }
        if (StringUtils.isNotEmpty(clientVo.getPassword())){
            wrapper.eq("password",clientVo.getPassword());
        }
        if (StringUtils.isNotEmpty(clientVo.getUsername())){
            wrapper.like("username",clientVo.getUsername());
        }

        Page<TbClient> page1=clientMapper.selectPage(page,wrapper);
        return R.ok().put("records",page1.getRecords()).put("total",page1.getTotal());
    }

    @Override
    public R deleteClient(Integer id) {
        int i=clientMapper.deleteById(id);
        return R.ok();
    }

    @Override
    public R updateClient(TbClient tbClient) {
        clientMapper.updateById(tbClient);
        return R.ok();
    }

    @Override
    public R insertClient(TbClient tbClient) {
        clientMapper.insert(tbClient);
        return R.ok();
    }
}